﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AAA.Algorithm.Data;

namespace AAA.Algorithm.Cluster.HSFC
{
    public class HSFC : AbstractCluster
    {
        private List<HSFCMapNode> _lstMapNode;
        private IFutureGroup _futureGroup;
        private float _fThreshold;

        public HSFC(IFutureGroup futureGroup)
        {
            _lstMapNode = new List<HSFCMapNode>();
            _futureGroup = futureGroup;
        }

        public float Threshold
        {
            get { return _fThreshold; }
            set { _fThreshold = value; }
        }

        protected override void PostCluster(float fSimilarity, float fMaxSimilarity, object oMapNodeKey, INeuron neuron, Dictionary<object, AbstractMapNode> dicCluster)
        {
            HSFCMapNode mapNode = null;
            try
            {
                if (oMapNodeKey == null)
                {
                    mapNode = new HSFCMapNode();
                    dicCluster.Add(dicCluster.Count, mapNode);
                    mapNode.AddSample(neuron);
                    return;
                }
                
                if (fMaxSimilarity < Threshold)
                {
                    dicCluster[oMapNodeKey].RemoveSample(neuron);
                    mapNode = new HSFCMapNode();
                    dicCluster.Add(dicCluster.Count, mapNode);
                    mapNode.AddSample(neuron);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "," + ex.StackTrace);
            }
        }

    }
}
